package br.edu.ufabc.gtrnp.helppo.business;

import static br.edu.ufabc.gtrnp.helppo.util.RPCOpenSimMethods.ADMIN_BROADCAST;
import static br.edu.ufabc.gtrnp.helppo.util.RPCOpenSimParameters.MENSAGEM;
import static br.edu.ufabc.gtrnp.helppo.util.RPCOpenSimParameters.SERVER_PASSWORD;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.client.XmlRpcClient;

import br.edu.ufabc.gtrnp.helppo.util.HelppoProperties;
import br.edu.ufabc.gtrnp.helppo.util.RpcClientSingleton;

public class BroadcastBusiness {
	private static BroadcastBusiness business = new BroadcastBusiness();

	private BroadcastBusiness() {
	}

	public static BroadcastBusiness getInstance() {
		return business;
	}

	public void enviarMensagem(String mensagem) throws IOException, XmlRpcException {
		XmlRpcClient client = RpcClientSingleton.getInstance();
		client.execute(ADMIN_BROADCAST, parameter(mensagem));

	}

	private List<Hashtable<String, String>> parameter(String mensagem)
			throws IOException {
		Hashtable<String, String> parameters = new Hashtable<String, String>();

		parameters.put(MENSAGEM, mensagem);
		parameters.put(SERVER_PASSWORD, HelppoProperties.getInstance()
				.getString(SERVER_PASSWORD));

		List<Hashtable<String, String>> list = new ArrayList<Hashtable<String, String>>();
		list.add(parameters);

		return list;
	}
}
